  package com.weixin.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;


@WebFilter("/*")
public class EncodFilter implements Filter {

    /**
     * Default constructor. 
     */
    public EncodFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request=(HttpServletRequest) servletRequest;
		String uri = request.getRequestURI();
		if(uri.contains("js")) {
			chain.doFilter(servletRequest, servletResponse);
		}else {	
			servletRequest.setCharacterEncoding("utf-8");
			servletResponse.setCharacterEncoding("utf-8");
			servletResponse.setContentType("text/html;charset=utf-8");
			chain.doFilter(servletRequest, servletResponse);
		}
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
